home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.5)
-
- import ctypes
- import _winreg
- import config
- import prefs
- import os
- import logging
- import resources
- import sys
- import urllib
- from util import returnsUnicode, returnsBinary, checkU, checkB, call_command, AutoflushingStream
- localeInitialized = False
- FilenameType = unicode
-
- def samefile(path1, path2):
- return getLongPathName(path1) == getLongPathName(path2)
-
-
- def getLongPathName(path):
- buf = ctypes.create_unicode_buffer(260)
- GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
- rv = GetLongPathName(path, buf, 260)
- if rv == 0 or rv > 260:
- return path
- else:
- return buf.value
-
-
- def getAvailableBytesForMovies():
- moviesDir = config.get(prefs.MOVIES_DIRECTORY)
- freeSpace = ctypes.c_ulonglong(0)
- availableSpace = ctypes.c_ulonglong(0)
- totalSpace = ctypes.c_ulonglong(0)
- rv = ctypes.windll.kernel32.GetDiskFreeSpaceExW(unicode(moviesDir), ctypes.byref(availableSpace), ctypes.byref(totalSpace), ctypes.byref(freeSpace))
- if rv == 0:
- print 'GetDiskFreeSpaceExW failed, returning bogus value!'
- return 0x1900000000L
-
- return availableSpace.value
-
- _langs = {
- 1025: 'ar',
- 1046: 'pt_BR',
- 2052: 'zh_CN',
- 1028: 'zh_TW',
- 1029: 'cs',
- 1030: 'da',
- 1043: 'nl',
- 1035: 'fi',
- 1036: 'fr',
- 1031: 'de',
- 1032: 'el',
- 1037: 'he',
- 1038: 'hu',
- 1040: 'it',
- 1041: 'jp',
- 1042: 'ko',
- 1044: 'nb',
- 1045: 'pl',
- 2070: 'pt',
- 1049: 'ru',
- 3082: 'es',
- 1053: 'sv',
- 1055: 'tr' }
-
- def _getLocale():
- code = ctypes.windll.kernel32.GetUserDefaultUILanguage()
-
- try:
- return _langs[code]
- except:
- return None
-
-
-
- def initializeLocale():
- global localeInitialized
- lang = _getLocale()
- if lang:
- os.environ['LANGUAGE'] = lang
-
- localeInitialized = True
-
- _loggingSetup = False
-
- def setupLogging(inDownloader = False):
- global _loggingSetup
- if _loggingSetup:
- return None
-
- if not inDownloader:
- logFile = config.get(prefs.LOG_PATHNAME)
- logStream = open(logFile, 'wt')
- sys.stdout = sys.stderr = AutoflushingStream(logStream)
- else:
- logStream = sys.stderr
- logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s %(levelname)-8s %(message)s', stream = logStream)
- _loggingSetup = True
-
-
- def unicodeToFilename(filename, path = None):
-
- def shortenFilename(filename):
- checkU(filename)
- pieces = filename.split(u'.')
- lastpart = pieces[-1]
- if len(pieces) > 1:
- firstpart = u'.'.join(pieces[:-1])
- else:
- firstpart = u''
- if len(firstpart) > 0:
- return u'%s.%s' % (firstpart[:-1], lastpart)
- else:
- return filename[:-1]
-
- shortenFilename = returnsUnicode(shortenFilename)
- checkU(filename)
- if path:
- checkU(path)
- else:
- path = os.getcwd()
- MAX_LEN = 200
- filename.replace('/', '_').replace('\x00', '_').replace('\\', '_').replace(':', '_').replace('*', '_').replace('?', '_').replace('"', '_').replace('<', '_').replace('>', '_').replace('|', '_')
- newFilename = filename
- while len(newFilename) > MAX_LEN:
- newFilename = shortenFilename(newFilename)
- return newFilename
-
- unicodeToFilename = returnsUnicode(unicodeToFilename)
-
- def filenameToUnicode(filename, path = None):
- if path:
- checkU(path)
-
- checkU(filename)
- return filename
-
- filenameToUnicode = returnsUnicode(filenameToUnicode)
-
- def osFilenameToFilenameType(filename):
- return FilenameType(filename)
-
-
- def osFilenamesToFilenameTypes(filenames):
- return [ osFilenameToFilenameType(filename) for filename in filenames ]
-
-
- def filenameTypeToOSFilename(filename):
- return filename
-
-
- def makeURLSafe(string, safe = '/'):
- checkU(string)
- return urllib.quote(string.encode('utf_8'), safe = safe).decode('ascii')
-
- makeURLSafe = returnsUnicode(makeURLSafe)
-
- def unmakeURLSafe(string):
- checkU(string)
- return urllib.unquote(string.encode('ascii')).decode('utf_8')
-
- unmakeURLSafe = returnsUnicode(unmakeURLSafe)
-
- def resizeImage(source_path, dest_path, width, height):
- """Resize an image to a smaller size.
-
- Guidelines:
-
- Don't try to expand up the image.
-
- Don't change the aspect ratio
-
- The final image should be have the exact dimensions <width>X<height>. If
- there is extra room, either because the source image was smaller
- specified, or because it had a different aspect ratio, pad out the image
- with black pixels.
- """
- convert_path = os.path.join(resources.appRoot(), '..', 'imagemagick', 'convert.exe')
- border_width = max(width, height) / 2
- call_command(convert_path, source_path, '-strip', '-resize', '%dx%d>' % (width, height), '-gravity', 'center', '-bordercolor', 'black', '-border', '%s' % border_width, '-crop', '%dx%d+0+0' % (width, height), '+repage', dest_path)
-
-